package cc.eddic.pratice.programmingparadigms.emp02list.impl;

import cc.eddic.pratice.programmingparadigms.Employee;
import cc.eddic.pratice.programmingparadigms.emp02list.EmployeeList;


public class EmployeeListHrjImpl implements EmployeeList {

    private Employee[] employees;
    private int index;

    public EmployeeListHrjImpl(int capacity) {
        employees = new Employee[capacity];
    }

    @Override
    public void add(Employee employee) {
        if (index==employees.length) {
            Employee[] temp = new Employee[employees.length * 2];
            System.arraycopy(employees, 0, temp, 0, employees.length);
            employees = temp;
        }
        employees[index] = employee;
        index++;
    }

    @Override
    public Employee get(int index) {
        if (index < 0 || index >= size()) {
            throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size());
        }
        return employees[index];
    }

    @Override
    public int size() {
        return index;
    }
}
